/**	
	Description: for the wishlist seletor
	Author:      chenshangxuan
	
	TODO
	wishlist_dg_checkName:"<i18n:msg key="wishlist.dialog.checkName"/>",
	wishlist_dg_selectItem:"<i18n:msg key="wishlist.dialog.selectItem"/>",
	wishlist_dg_addSuccess:"<i18n:msg key="wishlist.dialog.addSuccess"/>",
	wishlist_dg_addExist:"<i18n:msg key="wishlist.dialog.addExist"/>",
	wishlist_dg_title:"<i18n:msg key="wishlist.dialog.title"/>",
	wishlist_my:"<i18n:msg key="product.addWishList.hint"/>",
**/


var url=__ctxPath + "/customer/selectWishlistDlg.html?decorator=blank&doAction=wishlistSelector";


function WishlistSelector(){
}

var dlgWishList=null;
var refreshIndex=1; //用于去除缓存
WishlistSelector.showDlg=function(){
        	if (dlgWishList ==null)
        	{
        		dlgWishList = fnCreateSimpleDialog("WishList",__FMT.wishlist_my,null,{
					dialogWidth:"520px",
					dialogHeight:"450px"
				});
        	}
        	refreshIndex +=1;
       		dlgWishList.showDialog(url+"&"+refreshIndex);
}
/*
	close the wishlist
*/
WishlistSelector.closeDlg=function(){
	if (dlgWishList!=null)
		dlgWishList.closeDialog();
}

/*
	add to wishlist 
*/
WishlistSelector.addToWishlist=function(){

	var wishlistIds=document.getElementsByName("opWishlistId");
	var wishlistId=-1;

	for(var i=0;i< wishlistIds.length;i++){
		if(wishlistIds[i].checked){
			wishlistId=wishlistIds[i].value;
			break;
		}
	}

	if(wishlistId==0){
		var	txtWishlistName=$("txtWishlistName");
		if(trim(txtWishlistName.value)==""){
			alert(__FMT.wishlist_dg_checkName);
			return;
		}
	}else if(wishlistId==-1){
		alert(__FMT.wishlist_dg_selectItem);
		return;
	}
	var result="";
	var productCode=$("productCode").value;
	//create new wishlist first when create new is asked,then add a item to wishlist
	var wishlistName=$("txtWishlistName").value;
	dlgWishList.closeDialog();
	wishlistManager.addSaveWishListItem(wishlistId,wishlistName,productCode,{callback:function(data){result=data;},async:false	});
	if(result=="success"){
		alert(__FMT.wishlist_dg_addSuccess);
	}else if(result=="exist"){
		alert(__FMT.wishlist_dg_addExist);
	}else if(result=="unlogin"){
		if(confirm(__FMT.wishlist_dg_loginConfirm)){
			location.href=__ctxPath+ "/customer/wishlist.html";
		}
	}
	
	
}
